﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System .Windows .Forms ;

namespace HuanGis
{
  public   class TreeViewHelper
    {


        FLayerManager m_lm;
        TreeView m_tv;

        PropertyGrid m_prop;

      public TreeViewHelper(FLayerManager m,TreeView tv,PropertyGrid  pg)
      {
          m_lm = m;
          m_tv = tv;
          m_prop = pg;

          //进行对应的事件封装

          m_lm.LayerSystem.LayerAdded += new LayerAddHandler(m_lm_LayerAdded);

          m_tv.NodeMouseClick += new TreeNodeMouseClickEventHandler(m_tv_NodeMouseClick);

      }


      void m_tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
      {
         

        FLayer layer=  m_lm.GetLayer( e.Node.Name);

        m_prop.SelectedObject = layer;
          
      }

      void m_lm_LayerAdded(FLayer layer)
      {

           m_tv.Nodes.Add(layer.Id, layer.descString);


          FCompoundLayer cl = layer as FCompoundLayer;
          if (cl != null)
          {
             
     
              foreach (FLayer  item in cl.Childs.Values  )
              {

                  m_tv.Nodes[layer.Id].Nodes.Add(item .Id ,item.descString );
              }

          }
 
          
           
         
      }



   
    }
}
